<template>
	<view class="colle page bgf6">




		<view class="bgff flex flexC flexB px20 py16 borb fs16">
			<text>主板编号</text>
			<view class="flex flexC">

				<view>
					<input v-model="device_sn" class="c8e px8"></input>
				</view>
				<image @click="clickScan" class="scan" src="../static/scan.png"></image>
			</view>
		</view>

		<view class="bgff flex flexC flexB px20 py16 borb fs16">
			<text>主板后5位数</text>
			<view class="flex flexC">

				<view>
					<text class="c8e px8 bold8">{{device.sim}}</text>
				</view>
				<text class="arrowR dinline mt2"></text>
			</view>
		</view>

		<view class="bgff flex flexC flexB px20 py16 borb fs16">
			<text>序号</text>
			<view class="flex flexC">

				<view>
					<text class="c8e px8 bold8">{{device.flag}}</text>
				</view>
				<text class="arrowR dinline mt2"></text>
			</view>
		</view>

		<picker :range="brand" @change="clickBrand">
			<view class="bgff flex flexC flexB px20 py16 borb fs16">
				<text>品牌标识</text>

				<view class="flex flexC">

					<view>
						<text class="c8e px8 bold8">{{brandSelect}}</text>
					</view>
					<text class="arrowR dinline mt2"></text>
				</view>

			</view>
		</picker>


		<button @click="getInfo" hover-class="none" class="r40 bg41 m10 fs16 py16">读取信息</button>


	</view>
</template>

<script>
	export default {
		data() {
			return {

				device_sn: '',
				device: null,
				brand: [],
				brandSelect: ''
			};
		},
		onLoad() {
			this.getBrand();
		},
		onShow() {},
		methods: {

			clickBrand(e) {
				var b = this.brand[e.detail.value];



				let param = {
					device_sn: this.device_sn,
					brand: b
				};
				let that = this;
				this.$api.testUpdateDeviceBrand(param).then(res => {

					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
					if (res.code == 1) {
						that.brandSelect = b;
					} else {

					}
				})
			},
			openRoomCmd(time) {

				let param = {
					device_sn: this.device.device_sn,
					sn: this.device.sn,
					sec: time
				};
				let that = this;
				this.$api.testOpen(param).then(res => {

					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
					if (res.code == 1) {

					} else {

					}
				})
			},

			clickScan() {
				let that = this;
				uni.scanCode({
					onlyFromCamera: false, // 是否只从相机扫码，不从相册选择图片
					scanType: ['qrCode', 'barCode'], // 扫描的类型
					success: function(res) {
						that.device_sn = res.result;
						console.log('扫描结果：', res.result);
						console.log('扫描条码类型：', res.scanType);
						console.log('字符集：', res.charSet);
						console.log('路径：', res.path); // 当所扫的码为小程序码时会返回此项
						that.getInfo();
					},
					fail: function(err) {
						console.error('扫码失败：', err);
					},
					complete: function() {
						console.log('扫码操作完成');
					}
				});

			},


			getBrand() {
				let param = {
					device_sn: this.device_sn
				}
				let that = this;
				this.$api.testBrand(param).then(res => {
					console.info(res);
					if (res.code == 1) {
						that.brand = res.data;

					} else {

					}
				})

			},


			getInfo() {
				let param = {
					device_sn: this.device_sn
				}
				let that = this;
				this.$api.testInfo2(param).then(res => {
					console.info(res);
					if (res.code == 1) {
						that.device = res.data;
						that.brandSelect = res.data.brand;

					} else {

					}
				})

			}

		}
	}
</script>

<style lang="scss" scoped>
	.colle {

		.scan {
			width: 100rpx;
			height: 100rpx;
		}

		.head {
			width: 90rpx;
			height: 90rpx;
		}

		.w20 {
			width: 80rpx;
			height: 80rpx;
		}

		.w28 {
			width: 56rpx;
		}

		.maxH {
			height: 60vh;
		}
	}
</style>